home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 15 / CU Amiga Magazine's Super CD-ROM 15 (1997)(EMAP Images)(GB)[!][issue 1997-10].iso / CUCD / Graphics / Ghostscript / source / libpng / pngerror.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-12  |  3.8 KB  |  113 lines

  1.  
  2. /* pngerror.c - stub functions for i/o and memory allocation
  3.  
  4.    libpng 1.0 beta 6 - version 0.96
  5.    For conditions of distribution and use, see copyright notice in png.h
  6.    Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
  7.    Copyright (c) 1996, 1997 Andreas Dilger
  8.    May 12, 1997
  9.  
  10.    This file provides a location for all error handling.  Users which
  11.    need special error handling are expected to write replacement functions
  12.    and use png_set_error_fn() to use those functions.  See the instructions
  13.    at each function. */
  14.  
  15. #define PNG_INTERNAL
  16. #include "png.h"
  17.  
  18. static void png_default_error PNGARG((png_structp png_ptr,
  19.                                       png_const_charp message));
  20. static void png_default_warning PNGARG((png_structp png_ptr,
  21.                                         png_const_charp message));
  22.  
  23. /* This function is called whenever there is a fatal error.  This function
  24.    should not be changed.  If there is a need to handle errors differently,
  25.    you should supply a replacement error function and use png_set_error_fn()
  26.    to replace the error function at run-time. */
  27. void
  28. png_error(png_structp png_ptr, png_const_charp message)
  29. {
  30.    if (png_ptr->error_fn != NULL)
  31.       (*(png_ptr->error_fn))(png_ptr, message);
  32.  
  33.    /* if the following returns or doesn't exist, use the default function,
  34.       which will not return */
  35.    png_default_error(png_ptr, message);
  36. }
  37.  
  38. /* This function is called whenever there is a non-fatal error.  This function
  39.    should not be changed.  If there is a need to handle warnings differently,
  40.    you should supply a replacement warning function and use
  41.    png_set_error_fn() to replace the warning function at run-time. */
  42. void
  43. png_warning(png_structp png_ptr, png_const_charp message)
  44. {
  45.    if (png_ptr->warning_fn != NULL)
  46.       (*(png_ptr->warning_fn))(png_ptr, message);
  47.    else
  48.       png_default_warning(png_ptr, message);
  49. }
  50.  
  51. /* This is the default error handling function.  Note that replacements for
  52.    this function MUST NOT RETURN, or the program will likely crash.  This
  53.    function is used by default, or if the program supplies NULL for the
  54.    error function pointer in png_set_error_fn(). */
  55. static void
  56. png_default_error(png_structp png_ptr, png_const_charp message)
  57. {
  58. #ifndef PNG_NO_STDIO
  59.    fprintf(stderr, "libpng error: %s\n", message);
  60. #endif
  61.  
  62. #ifdef USE_FAR_KEYWORD
  63.    {
  64.       jmp_buf jmpbuf;
  65.       png_memcpy(jmpbuf,png_ptr->jmpbuf,sizeof(jmp_buf));
  66.       longjmp(jmpbuf, 1);
  67.    }
  68. #else
  69.    longjmp(png_ptr->jmpbuf, 1);
  70. #endif
  71. }
  72.  
  73. /* This function is called when there is a warning, but the library thinks
  74.    it can continue anyway.  Replacement functions don't have to do anything
  75.    here if you don't want to.  In the default configuration, png_ptr is
  76.    not used, but it is passed in case it may be useful. */
  77. static void
  78. png_default_warning(png_structp png_ptr, png_const_charp message)
  79. {
  80.    if (png_ptr == NULL)
  81.       return;
  82.  
  83. #ifndef PNG_NO_STDIO
  84.    fprintf(stderr, "libpng warning: %s\n", message);
  85. #endif
  86. }
  87.  
  88. /* This function is called when the application wants to use another method
  89.    of handling errors and warnings.  Note that the error function MUST NOT
  90.    return to the calling routine or serious problems will occur.  The return
  91.    method used in the default routine calls longjmp(png_ptr->jmpbuf, 1) */
  92. void
  93. png_set_error_fn(png_structp png_ptr, png_voidp error_ptr,
  94.    png_error_ptr error_fn, png_error_ptr warning_fn)
  95. {
  96.    png_ptr->error_ptr = error_ptr;
  97.    png_ptr->error_fn = error_fn;
  98.    png_ptr->warning_fn = warning_fn;
  99. }
  100.  
  101.  
  102. /* This function returns a pointer to the error_ptr associated with the user
  103.    functions.  The application should free any memory associated with this
  104.    pointer before png_write_destroy and png_read_destroy are called. */
  105. png_voidp
  106. png_get_error_ptr(png_structp png_ptr)
  107. {
  108.    return png_ptr->error_ptr;
  109. }
  110.  
  111.  
  112.  
  113.